﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;

namespace Team4Mock.DAO
{
    public class DepartmentDAO
    {
        Helper h=new Helper();
        /// <summary>
        /// Get data theo ID Directorate
        /// </summary>
        /// <param name="idDirec"></param>
        /// <returns></returns>
        public DataTable GetDataByID(int idDirec)
        {
            SqlParameter[]p=new SqlParameter[1];
            p[0]=new SqlParameter("@id",idDirec);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Department_Getdata", p);
        }

        public void Del(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Department_Del", p);
        }

        /// <summary>
        /// Get data theo ID Department
        /// </summary>
        /// <param name="idDepartment"></param>
        /// <returns></returns>
        public DataTable GetByID(int idDepartment)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", idDepartment);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Department_GetdataByID", p);
        }
        public void Insert(string name, string shortdes, int contact, string add1, string add2, string add3, string post, string town, string county, string country, string bus, string sic, string full, string phone, string fax, string web, string charity, string company, int iddirec, int active)
        {
            SqlParameter[] p = new SqlParameter[20];
            p[0] = new SqlParameter("@name", name);
            p[0].SqlDbType = SqlDbType.NVarChar;
            p[1] = new SqlParameter("@short", shortdes);
            p[1].SqlDbType = SqlDbType.NVarChar;
            p[2] = new SqlParameter("@contact", contact);
            p[2].SqlDbType = SqlDbType.Int;
            p[3] = new SqlParameter("@add1", add1);
            p[3].SqlDbType = SqlDbType.NVarChar;
            p[4] = new SqlParameter("@add2", add2);
            p[4].SqlDbType = SqlDbType.NVarChar;
            p[5] = new SqlParameter("@add3", add3);
            p[5].SqlDbType = SqlDbType.NVarChar;
            p[6] = new SqlParameter("@post", post);
            p[6].SqlDbType = SqlDbType.VarChar;
            p[7] = new SqlParameter("@town", town);
            p[7].SqlDbType = SqlDbType.NVarChar;
            p[8] = new SqlParameter("@county", county);
            p[8].SqlDbType = SqlDbType.NVarChar;
            p[9] = new SqlParameter("@country", country);
            p[9].SqlDbType = SqlDbType.NVarChar;
            p[10] = new SqlParameter("@bus", bus);
            p[10].SqlDbType = SqlDbType.NVarChar;
            p[11] = new SqlParameter("@sic", sic);
            p[11].SqlDbType = SqlDbType.VarChar;
            p[12] = new SqlParameter("@full", full);
            p[12].SqlDbType = SqlDbType.NVarChar;
            p[13] = new SqlParameter("@phone", phone);
            p[13].SqlDbType = SqlDbType.VarChar;
            p[14] = new SqlParameter("@fax", fax);
            p[14].SqlDbType = SqlDbType.VarChar;

            p[15] = new SqlParameter("@web", web);
            p[15].SqlDbType = SqlDbType.VarChar;
            p[16] = new SqlParameter("@charity", charity);
            p[16].SqlDbType = SqlDbType.VarChar;
            p[17] = new SqlParameter("@company", company);
            p[17].SqlDbType = SqlDbType.VarChar;
            p[18] = new SqlParameter("@iddirec", iddirec);
            p[18].SqlDbType = SqlDbType.Int;
            p[19] = new SqlParameter("@active", active);
            p[19].SqlDbType = SqlDbType.Int;

            h.ExecuteNonQuerry("Department_Create", p);
        }
        public void Update(string name, string shortdes, int contact, string add1, string add2, string add3, string post, string town, string county, string country, string bus, string sic, string full, string phone, string fax, string web, string charity, string company, int active, int id)
        {
            SqlParameter[] p = new SqlParameter[20];
            p[0] = new SqlParameter("@name", name);
            p[0].SqlDbType = SqlDbType.NVarChar;
            p[1] = new SqlParameter("@short", shortdes);
            p[1].SqlDbType = SqlDbType.NVarChar;
            p[2] = new SqlParameter("@contact", contact);
            p[2].SqlDbType = SqlDbType.Int;
            p[3] = new SqlParameter("@add1", add1);
            p[3].SqlDbType = SqlDbType.NVarChar;
            p[4] = new SqlParameter("@add2", add2);
            p[4].SqlDbType = SqlDbType.NVarChar;
            p[5] = new SqlParameter("@add3", add3);
            p[5].SqlDbType = SqlDbType.NVarChar;
            p[6] = new SqlParameter("@post", post);
            p[6].SqlDbType = SqlDbType.VarChar;
            p[7] = new SqlParameter("@town", town);
            p[7].SqlDbType = SqlDbType.NVarChar;
            p[8] = new SqlParameter("@county", county);
            p[8].SqlDbType = SqlDbType.NVarChar;
            p[9] = new SqlParameter("@country", country);
            p[9].SqlDbType = SqlDbType.NVarChar;
            p[10] = new SqlParameter("@bus", bus);
            p[10].SqlDbType = SqlDbType.NVarChar;
            p[11] = new SqlParameter("@sic", sic);
            p[11].SqlDbType = SqlDbType.VarChar;
            p[12] = new SqlParameter("@full", full);
            p[12].SqlDbType = SqlDbType.NVarChar;
            p[13] = new SqlParameter("@phone", phone);
            p[13].SqlDbType = SqlDbType.VarChar;
            p[14] = new SqlParameter("@fax", fax);
            p[14].SqlDbType = SqlDbType.VarChar;

            p[15] = new SqlParameter("@web", web);
            p[15].SqlDbType = SqlDbType.VarChar;
            p[16] = new SqlParameter("@charity", charity);
            p[16].SqlDbType = SqlDbType.VarChar;
            p[17] = new SqlParameter("@company", company);
            p[17].SqlDbType = SqlDbType.VarChar;
            
            p[18] = new SqlParameter("@active", active);
            p[18].SqlDbType = SqlDbType.Int;
            p[19] = new SqlParameter("@id", id);
            p[19].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Department_Update", p);
        }
        public DataTable CopyOrg(int idorg)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@idorg", idorg);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Department_CopyOrg", p);
        }
        public DataTable CopyDirec(int iddirec)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@iddirec", iddirec);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Department_CopyDirec", p);
        }
    }
}